package com.yuanfeng.job.service.impl;

import com.yuanfeng.commoms.util.DateUtils;
import com.yuanfeng.commoms.vo.order.CommissionSettleVO;
import com.yuanfeng.commoms.vo.payment.PayFxAccountVO;
import com.yuanfeng.commoms.vo.payment.PayFxRecordVO;
import com.yuanfeng.job.service.PayFxService;
import org.apache.commons.lang.RandomStringUtils;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * @ClassName PayFxServiceImpl
 * @Description
 * @Author hyq
 * @Date 2023/9/5 13:42
 * @Version 1.0
 **/
@Service
public class PayFxServiceImpl implements PayFxService {
    @Override
    public PayFxRecordVO buildFxRecord(CommissionSettleVO commissionSettle, PayFxAccountVO payFxAccount) {
        String recordId = "R" + DateUtils.getTimeStamp()+ RandomStringUtils.randomNumeric(8);
        PayFxRecordVO payFxRecord = new PayFxRecordVO();
        payFxRecord.setRecordId(recordId);
        payFxRecord.setUserId(commissionSettle.getShareUserId());
        payFxRecord.setUserName(commissionSettle.getShareUserName());
        payFxRecord.setRecordAmount(commissionSettle.getCommissionMoney());
        BigDecimal userVkAccount = (null==payFxAccount || null==payFxAccount.getVkAccount())? BigDecimal.ZERO:payFxAccount.getVkAccount();
        BigDecimal userYGAccount = (null==payFxAccount || null==payFxAccount.getYgAccount())? BigDecimal.ZERO:payFxAccount.getYgAccount();
        if(commissionSettle.getCommissionType().intValue() == 1) {
            payFxRecord.setBeforeRecordAmount(userVkAccount);
            payFxRecord.setAfterRecordAmount(userVkAccount.add(commissionSettle.getCommissionMoney()));
        }else{
            payFxRecord.setBeforeRecordAmount(userYGAccount);
            payFxRecord.setAfterRecordAmount(userYGAccount.add(commissionSettle.getCommissionMoney()));
        }
        payFxRecord.setRecordStatus(2);
        payFxRecord.setTradeTypeId(1);
        payFxRecord.setRecordType(commissionSettle.getCommissionType());
        payFxRecord.setPlusOrMinus(1);
        payFxRecord.setRecordName("结算佣金");
        payFxRecord.setRecordStatusName("结算成功");
        payFxRecord.setRecordDate(DateUtils.getNowDay());
        payFxRecord.setCreateTime(DateUtils.getNowDateToString());
        payFxRecord.setUpdateTime(DateUtils.getNowDateToString());
        return payFxRecord;
    }

    @Override
    public PayFxAccountVO buildFXAccount(CommissionSettleVO commissionSettle) {
        PayFxAccountVO payFxAccount = new PayFxAccountVO();
        payFxAccount.setUserId(commissionSettle.getShareUserId());
        payFxAccount.setUserName(commissionSettle.getShareUserName());
        payFxAccount.setUserMobile(commissionSettle.getShareUserMobile());
        payFxAccount.setTotalAccount(commissionSettle.getCommissionMoney());
        if(commissionSettle.getCommissionType().intValue() == 1) {
            payFxAccount.setVkAccount(commissionSettle.getCommissionMoney());
        }else{
            payFxAccount.setYgAccount(commissionSettle.getCommissionMoney());
        }
        payFxAccount.setCreateTime(DateUtils.getNowDateToString());
        payFxAccount.setUpdateTime(DateUtils.getNowDateToString());
        return payFxAccount;
    }
}
